var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
    })(t, e);
}, function(t, e) {
    function i() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype, 
    new i());
}), a = this && this.__decorate || function(t, e, i, o) {
    var r, s = arguments.length, n = s < 3 ? e : null === o ? o = Object.getOwnPropertyDescriptor(e, i) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, o); else for (var a = t.length - 1; 0 <= a; a--) (r = t[a]) && (n = (s < 3 ? r(n) : 3 < s ? r(e, i, n) : r(e, i)) || n);
    return 3 < s && n && Object.defineProperty(e, i, n), n;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameConfig"), s = e("GameData"), c = e("GameManager"), l = e("Global"), d = e("GameBlock"), u = e("GameItem"), p = cc._decorator, h = p.ccclass, f = (p.property, 
function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.HP = 1e3, t.isStart = !1, t.isHurt = !1, t.isDestory = !1, t.shadow = null, 
        t;
    }
    return i(t, e), t.prototype.init = function(i) {
        var o = this;
        return new Promise(function(e, t) {
            o.gameView || (o.gameView = c.default.getInstance().gameView), o.gameView ? o.gameView.appendSprite({
                url: i,
                root: o.gameView.layout,
                pos: cc.v2(o.node.x, o.node.y + 130)
            }).then(function(t) {
                o.sprite = t, o.sprite.node.zIndex = o.node.zIndex, o.sprite.node.angle = 0, o.sprite.node.anchorY = 0, 
                o.doAction(), e();
            }, function() {
                t();
            }) : t();
        });
    }, t.prototype.doHurt = function(t) {
        return !this.isStart || e.prototype.doHurt.call(this, t);
    }, t.prototype.doDestroy = function() {
        var t, e;
        this.isDestory || (this.doDrop(this.getItemList()), this.isDestory = !0, this.shadow && this.gameView.removeSprite(this.shadow), 
        this.sprite && cc.Tween.stopAllByTarget(this.sprite.node), this.gameView || (this.gameView = c.default.getInstance().gameView), 
        this.gameView && (-1 == this.gameView.astar.gridsList[this.gird.x][this.gird.y].type && (this.gameView.astar.gridsList[this.gird.x][this.gird.y].type = 0, 
        this.gameView.astar.gridsList[this.gird.x][this.gird.y].target = null), this.gameView.blocks.splice(this.gameView.blocks.indexOf(this), 1), 
        this.sprite && this.gameView.removeSprite(this.sprite.node), s.GD.isVibrate && (null === (e = null === (t = GA.PA) || void 0 === t ? void 0 : t.vibrateShort) || void 0 === e || e.call(t, {})), 
        this.node.destroy()));
    }, t.prototype.doDrop = function(t) {
        for (var e = 0; e < t.length; e++) {
            var i = t[e], o = this.gameView.checkEmptyGird(this.gird.x - 3, this.gird.y - 3, this.gird.x + 3, this.gird.y + 3);
            if (!o) break;
            var r = this.gameView.getItem();
            r.setPosition(o.scaleSelf(cc.v2(this.node.width, this.node.height)).addSelf(cc.v2((this.node.width - this.gameView.map.width) / 2, (this.node.height - this.gameView.map.height) / 2))), 
            r.parent = this.node.parent, r.zIndex = 2 * -o.y, r.getComponent(u.default).init(l.ItemType.CHRISTMAS, i), 
            c.default.getInstance().gameView.items.push(r.getComponent(u.default));
        }
    }, t.prototype.doAction = function() {
        var t = this;
        this.isDestory || this.sprite && cc.tween(this.sprite.node).by(.5, {
            position: cc.v3(0, -150)
        }).call(function() {
            t.isStart = !0;
        }).repeatForever(cc.tween().by(1, {
            position: cc.v2(0, 15)
        }).by(1, {
            position: cc.v2(0, -15)
        })).start();
    }, t.prototype.addShadow = function() {
        var e = this;
        this.gameView.appendSprite({
            url: "texture/battle/shadow",
            root: this.gameView.bottom,
            pos: this.node.getPosition().add(cc.v2(0, -20))
        }).then(function(t) {
            e.isDestory ? c.default.getInstance().gameView.removeSprite(t.node) : (e.shadow = t.node, 
            t.node.active = !0, t.node.scale = .7, t.node.angle = 0, t.node.zIndex = -2);
        });
    }, t.prototype.getItemList = function() {
        for (var t = [], e = 0; e < r.GC.christmasDropConfig.length; e++) {
            var i = r.GC.christmasDropConfig[e];
            if (GA.rand(0, 100) < i.percent) switch (i.type) {
              case 0:
                t.push({
                    type: i.type,
                    num: Math.floor(l.G.getPrice(s.GD.topRank - 1) * i.min / 100)
                });
                break;

              case 1:
              case 2:
                t.push({
                    type: i.type,
                    num: GA.rand(i.min, i.max)
                });
                break;

              case 3:
                t.push({
                    type: i.type,
                    idx: this.getId(),
                    time: Date.now() + r.GC.christmasSkinTime
                });
            }
        }
        return 0 == t.length && t.push({
            type: 1,
            num: 50
        }), t;
    }, t.prototype.getId = function() {
        return r.GC.christmasSkinIdList[GA.rand(0, r.GC.christmasSkinIdList.length - 1)];
    }, a([ h ], t);
}(d.default));

n.default = f;